package main

import (
	"fmt"
	"net/http"
)

type MyHandler struct {

}
// 处理器函数
func (h *MyHandler)ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Hello World", r.URL.Path,r.Method,r.Host)
	_,err:=w.Write([]byte("hello golang"))  //_忽略返回字节数
	if err!=nil{
		fmt.Println("write error=",err)
	}
	w.Write([]byte(r.Proto))  //协议
}

func main() {
	myhandler := MyHandler{}
	http.Handle("/my", &myhandler)
	http.ListenAndServe(":8000",nil)
	//自己详细配置,但是任何路由都能请求
	//server := http.Server{
	//	Addr: ":8000",
	//	Handler: &myhandler,
	//	ReadTimeout: 2 * time.Second,
	//
	//}
	//server.ListenAndServe()
}


